package qj.app.console;

import java.awt.Component;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTextField;

import qj.app.console.Config.Console;
import qj.util.SwingUtil;
import qj.util.SwingUtil.RowAdder;
import qj.util.funct.P1;

public class Configurator {

	private List<String> attrs;
	private List<String> globalAttrs;
	
//	public static class ConfigField {
//		public String fieldName;
//		public enum Types {
//			Path,Int
//		}
//	}

	public static Configurator defau(List<String> attrs) {
		Configurator configurator = new Configurator();
		configurator.attrs = attrs;
		return configurator;
	}

	public static Configurator defau(List<String> attrs, List<String> globalAttrs) {
		Configurator configurator = defau(attrs);
		configurator.globalAttrs = globalAttrs;
		return configurator;
	}

	public Component detailPane(final Console console) {
		JPanel pane = new JPanel();
		RowAdder ra = SwingUtil.rowAdder(pane);
		for (final String attr : attrs) {
			String text = console.properties.get(attr);
			JTextField tf = new JTextField(text);
			ra.row(attr, SwingUtil.fileSelectorPanel(tf));
			SwingUtil.onChange(tf, new P1<String>() {public void e(String newText) {
				console.properties.put(attr, newText);
				console.saveF.e();
			}});
		}
		return pane;
	}
	
}
